package com.lepu.app.fun.chat.business.album;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;

import com.eyzhs.app.R;
import com.lepu.app.fun.chat.adapter.AlbumListAdapter;
import com.lepu.app.fun.chat.controller.base.AbsBaseFragment;

import java.util.List;

import common.db.Constants;
import common.db.alummage.ImageBucket;


/**
 * 相册列表
 * Created by chuanyhu on 2014/8/2.
 */
public class AlbumListFragment extends AbsBaseFragment {

    private View fragView;
    public ImageView img_cancel;
    private ListView albumsListView;
    private List<ImageBucket> dataList;
    private AlbumListAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i("执行了基类的方法", "-----------------AlbumListFragment-----------------------");
        dataList = AlbumHelper.getHelper().getImagesBucketList(false);
//        dataList.addAll(list);
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        fragView = inflater.inflate(R.layout.chat_fragment_album_list, null);
        albumsListView = (ListView) fragView.findViewById(R.id.listview_albums);
        img_cancel = (ImageView) fragView.findViewById(R.id.bt_cancel);
        initView();
        return fragView;
    }

    /**
     * 初始化view视图
     */
    private void initView() {
        adapter = new AlbumListAdapter(getActivity(), dataList);
        albumsListView.setAdapter(adapter);

        albumsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                Bundle bundle = new Bundle();
                bundle.putSerializable(Constants.ImageBucket_ParamName, dataList.get(position));
                performBack(bundle);
            }

        });

        //取消
        img_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                performBack();
            }
        });
    }
}
